import time

from page.buy_page import BuyPage
from common.base import Base
from page.buy_page import url
from common.base import open_browser
from page.account_page import AccountPage
from page.order_page import OrderPage


class OrderScript():
    def __init__(self,driver):
        # 实例化浏览器和page类
        self.buy_page = BuyPage(driver)
        self.buy_page.open_url(url)
        self.acc_page = AccountPage(driver)
        self.order_page = OrderPage(driver)
        self.base = Base(driver)
    def buy_goods(self):
        """ 购买流程 """
        # 点击首页
        self.buy_page.click_sy()
        # 点击商品
        self.buy_page.click_goods()
        # 点击立即购买
        self.buy_page.click_submit()
        # 点击去结算
        self.acc_page.click_account()
        # 点击提交订单
        self.acc_page.click_order()
        time.sleep(5)
        # 点击用户中心
        self.order_page.click_uesr()
        time.sleep(5)
        # 点击我的订单
        self.order_page.click_myorder()

    def is_buy_success(self):
        # 判断是否购买成功
        try:
            res = self.order_page.order()
            res1 = self.order_page.order1()
            if res == res1:
                 print("购买成功")
            return res
        except Exception as e:
            return e


if __name__ == '__main__':
    driver = open_browser()
    order = OrderScript(driver)
    order.buy_goods()
    time.sleep(5)
    order.is_buy_success()




